<?php
include_once("../modules/checkA.php");
include_once("../../config.php");
$plate=select_one_line_all_items($table_Prefix."plate","mid = 'member'");
?>


<?
//用来判断当前系统属于什么板块
$system_part = $plate['mid'];

if(!$_REQUEST ['applydate'])
{
    $_REQUEST ['applydate']=date("Y-m");
}
$applydate  = addslashes($_REQUEST ['applydate']);

//include_once("collect-function.php");
?>

<?
//获取部门的 nid名字对应表
$department_full_list=select_lines_all_items($table_Prefix."department","","","");
$department_list=transform_2darray_in_1darray_with_new_key($department_full_list,"nid","name");

//获取员工的 nid名字对应表
$employee_full_list=select_lines_all_items($table_Prefix."employee","","","");
$employee_list=transform_2darray_in_1darray_with_new_key($employee_full_list,"nid","name");



?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <?php include ROOT_PATH_.'/controller/common/module/head.php'; ?>
    <?php include 'modules/head.php'; ?>

    <style>
        body .detail-staitics-info  {padding-top:25px;}
        body .detail-staitics-info h2{ display: none}
        body>.detail-staitics-info h2{ display: block; text-align: center}
        body>.detail-staitics-info .agent-list li{font-size: 12px!important; width:100px;}
        body>.detail-staitics-info .layui-table td, .layui-table th{font-size: 12px!important;}
    </style>




    <script language="javascript">
        //打印代码
        function Print()
        {
            var agentsum = document.getElementById("agentsum").value;




            var content = "";


for(i=0;i<agentsum;i++)
{

    var str = document.getElementById('agent'+i).innerHTML;     //获取需要打印的页面元素 ，page1元素设置样式page-break-after:always，意思是从下一行开始分割。
    content = content + str;
}



            var newstr = content;
            var oldstr = document.body.innerHTML;
            document.body.innerHTML =newstr;
            window.print();
            document.body.innerHTML=oldstr;



        }
    </script>





</head>

<body>

<div id="topbar"><?php include ROOT_PATH_.'/controller/common/module/topbar.php'; ?></div>

<div id="container" class="<? echo $system_part ?>">

    <div id="maincontent">

        <div id="sidebar">
            <?php include ROOT_PATH_.'/controller/common/module/sidebar.php'; ?>
        </div>




        <div id="content">
            <h1>介绍人明细</h1>
<div class="tips">
    1.退学的人数，按照开具退学发票的时间为准。只修改学员信息为退学，不计算在内
<br/>
2.数据正确的时候，退学人数和退学票据数目相同。否则请检查学员状态或票据类型是否正确</div>

            <input type="button" value="批量打印" onclick="Print()" class="layui-btn" />

            <!-- 用$system_part .list_boxes来控制来到确认板块信息显示-->
            <div class="list-box" >

                <div class="statistic">


                    <div class="term-select-function">
                        <label class="layui-form-label">筛选：</label>
                        <div class="layui-input-block">

<?
                            $oldest_men=select_one_line_all_items($table_Prefix."member","nid > 0 and applydate !='' and applydate is not null order by applydate asc");




                            date_default_timezone_set('Asia/Shanghai');
                            $first_day_of_month = date('Y-m',time()) . '-01 00:00:01';
                            $t = strtotime($first_day_of_month);

                            $oldest_month=substr($oldest_men['applydate'],0,7);

                            $endmark=10000;

                            for ($i = 0; $i < $endmark; $i++) {



                                if(date("Y-m",strtotime("-$i month",$t))==$oldest_month)
                                {
                                    $endmark=0;
                                    $showdate[$i]=date("Y-m",strtotime("-$i month",$t));
                                }
                                else
                                {

                                    $showdate[$i]=date("Y-m",strtotime("-$i month",$t));
                                }


                            }


                            ?>


                            <select name="jumpMenu" id="jumpMenu" onchange="MM_jumpMenu('parent',this,0)">
                                <option value=""> </option>
                                <?php
                                for ($i = 0; $i < count($showdate); $i++) {
                                    ?>
                                    <option value="agent-collect.php?applydate=<? echo $showdate[$i] ?>&nav-itemed=<? echo $system_part ?>"> <? echo $showdate[$i];?> </option>
                                    <?;}?>
                            </select>

                        </div>
                    </div>


                </div>


         <br class="clearfloat"/>




<input name="print" type="button" id="bt" value="点击打印" class="layui-btn" onclick="print_btn('detail-staitics-print')"/>





<div id="detail-staitics-print" >
<div class="detail-staitics-info" >
<h2>介绍人明细</h2>

    <?

    $summember=count_by_item($table_Prefix."member", "(sid is null or sid = '0') and applydate like '%".$applydate."%'","");


    $flunk_member_sum=count_by_item($table_Prefix."member", "(sid is null or sid = '0') and graduate = '退学' and graduatedate like '%".$applydate."%'","");

    $flunk_receipt_sum=count_by_item($table_Prefix."receipt", "type = '退学退费' and receiptdate like '%".$applydate."%'","");


    $sumcost=sum_total($table_Prefix."member","cost","(sid is null or sid = '0') and applydate like '%".$applydate."%'","");


    $flunk_sumcost=sum_total($table_Prefix."member","cost","(sid is null or sid = '0') and graduatedate like '%".$applydate."%'","");



    $full_detail=select_lines_all_items($table_Prefix."member","","(sid is null or sid = '0')  and applydate like '%".$applydate."%'","");

    $full_flunk_detail=select_lines_all_items($table_Prefix."member","","(sid is null or sid = '0')  and graduatedate like '%".$applydate."%' and graduate ='退学' ","");



    //获取所有驾照的类型，并且按照顺序重新排列。
    $license_list=two_d_array_item_in_one_d_array($full_detail,"license");
    asort($license_list);
    $number_range=array_count_values($license_list);
    $number_range_key=array_keys($number_range);



    //获取所有介绍人，并且按照顺序重新排列。
    $agent_list=two_d_array_item_in_one_d_array($full_detail,"agentid");

    $employee_number_range=array_count_values($agent_list);
    asort($employee_number_range);
    $employee_number_range_key=array_keys($employee_number_range);



    //退学部分
    //获取所有驾照的类型，并且按照顺序重新排列。
    $license_flunk_list=two_d_array_item_in_one_d_array($full_flunk_detail,"license");
    asort($license_flunk_list);
    $flunk_number_range=array_count_values($license_flunk_list);
    $flunk_number_range_key=array_keys($number_range);



    //获取所有介绍人，并且按照顺序重新排列。
    $flunk_agent_list=two_d_array_item_in_one_d_array($full_flunk_detail,"agentid");

    $flunk_employee_number_range=array_count_values($flunk_agent_list);
    asort($flunk_employee_number_range);
    $flunk_employee_number_range_key=array_keys($flunk_employee_number_range);

    ?>




    <input style="display:none " id="agentsum" value="<?echo count($employee_number_range_key)?>"  > </input>





<ul>

    <li><label>合计招生:</label><? echo $summember ?><b> 人</b></li>

    <li><label>合收金额:</label><? echo $sumcost ?><b> 元</b></li>

    <li><label>退学人数:</label><? echo $flunk_member_sum ?><b> 人</b></li>
    <li><label>退学票据:</label><? echo $flunk_receipt_sum ?><b> 张</b></li>

    <li><label>退学金额:</label><? echo $flunk_sumcost ?><b> 元</b></li>


</ul>


<h2>驾照类型 </h2>
    <ul>
        <?for($i=0;$i<count($number_range);$i++){?>
        <li><label><?echo $number_range_key[$i]?> : </label><?echo $number_range[$number_range_key[$i]]-$flunk_number_range[$number_range_key[$i]] ?><b> 人</b></li>
        <?;}?>
    </ul>

<hr/>



    <?

    if(in_array("admin",$quanxian)){?>
<h2>介绍人统计</h2>
    <ul class="agent-list">
        <?for($i=0;$i<count($employee_number_range);$i++){?>
            <? $agernt=select_one_line_all_items($table_Prefix."employee","nid = '".$employee_number_range_key[$i]."'")?>

            <li><label><?echo $agernt['name']?> : </label><?echo $employee_number_range[$employee_number_range_key[$i]]-$flunk_employee_number_range[$employee_number_range_key[$i]] ?><b> 人</b></b></li>
            <?;}?>
    </ul>

<hr/>
        <?;}?>















</div>
</div>















    <?


    for($i=0;$i<count($employee_number_range_key);$i++)
    {

        unset($detail);unset($sum_cost);
        $detail=select_lines_all_items($table_Prefix."member","","(sid is null or sid = '0') and agentid = '".$employee_number_range_key[$i]."' and  applydate like '%".$applydate."%'   ","");
        $flunk_detail=select_lines_all_items($table_Prefix."member","","(sid is null or sid = '0') and agentid = '".$employee_number_range_key[$i]."' and  graduatedate like '%".$applydate."%'  and graduate ='退学'  ","");

 ?>


        <span class="layui-btn layui-btn-small" onclick="print_btn(<?echo "'agent".$i."'"?>)">打印明细</span>

        <div class="list-boxes layui-form inprint" id="agent<?echo $i?>" >

            <h2> <? echo  $employee_list[$employee_number_range_key[$i]] ?></h2>











            <table class="layui-table" style="page-break-after:always">
                <colgroup>
                    <col width="60">
                    <col width="100">
                    <col >
                    <col width="120">
                    <col >
                    <col >
                    <col >
                    <col width="90">
                    <col width="90">
                    <col width="140">


                </colgroup>
                <thead>
                <tr>
                    <th>序号</th>
                    <th>姓名</th>
                    <th>编号</th>
                    <th>报名日期</th>
                    <th>驾照</th>
                    <th>金额</th>
                    <th>提成</th>
                    <th>付款状态</th>
                    <th>付款方式</th>
                    <th>结业状态</th>
                    <th>网点</th>
                </tr>
                </thead>
                <tbody>





                <?php
                for ($ii = 0; $ii < count($detail); $ii++) {
                    ?>

                    <tr <? if ($applymodify['nid']) {
                        echo "style='color:red'";
                        $status = "审核中";
                    } else {
                        $status = "正常";
                    } ?>>
                        <td><? echo $ii + 1 ?></td>
                        <td><? echo $detail[$ii]['name'] ?></td>
                        <td><? echo $detail[$ii]['mid'] ?></td>
                        <td><? echo substr($detail[$ii]['applydate'], 0, 10) ?></td>
                        <td><? echo $detail[$ii]['license'] ?></td>



                        <!--                                                --><?//
                        //                                                if($detail[$ii]['graduate']=="退学") {
                        //
                        //                                                    $detail[$ii]['cost']=-1*$detail[$ii]['cost'];
                        //
                        //                                                }?>

                        <td><? echo $detail[$ii]['cost'] ?> </td>

                        <td>
                            <?

                            //
                            //if($detail[$ii]['graduate']=="退学")
                            //{
                            //
                            //                                                    if (strpos($detail[$ii]['license'],"A")===0) {
                            //                                                        echo $commission[$ii]=-500;
                            //                                                    }
                            //                                                    if (strpos($detail[$ii]['license'],"B")===0) {
                            //                                                        echo  $commission[$ii]=-500;
                            //                                                    }
                            //                                                    if (strpos($detail[$ii]['license'],"C")===0) {
                            //                                                        echo $commission[$ii]=-200;
                            //                                                    }
                            //                                                    if (strpos($detail[$ii]['license'],"E")===0) {
                            //                                                        echo $commission[$ii]=-50;
                            //                                                    }
                            //
                            //
                            //}
                            //
                            //    else
                            //                                                    {
                            //
                            //


                            if (strpos($detail[$ii]['license'],"A")===0) {
                                echo $commission[$ii]=500;
                            }
                            if (strpos($detail[$ii]['license'],"B")===0) {
                                echo  $commission[$ii]=500;
                            }
                            if (strpos($detail[$ii]['license'],"C")===0) {
                                echo $commission[$ii]=200;
                            }
                            if (strpos($detail[$ii]['license'],"E")===0) {
                                echo $commission[$ii]=50;
                            }

                            //
                            //                                                    }

                            ?>
                        </td>


                        <td><? echo $detail[$ii]['status'] ?> </td>
                        <td><? echo $detail[$ii]['payment'] ?> </td>
                        <td><? echo $detail[$ii]['graduate'] ?> </td>
                        <td><? echo $department_list[$detail[$ii]['departmentid']] ?> </td>


                    </tr>

                    <? $sum_cost[$ii]=$detail[$ii]['cost']?>
                    <? $sum_commission[$ii]=$commission[$ii]?>

                    <?php
                    ;}
                ?>





                <?php
                for ($ii = 0; $ii < count($flunk_detail); $ii++) {
                    ?>

                    <tr <? if ($applymodify['nid']) {
                        echo "style='color:red'";
                        $status = "审核中";
                    } else {
                        $status = "正常";
                    } ?>>
                        <td><? echo count($detail) + 1 ?></td>
                        <td><? echo $flunk_detail[$ii]['name'] ?></td>
                        <td><? echo $flunk_detail[$ii]['mid'] ?></td>
                        <td><? echo substr($flunk_detail[$ii]['applydate'], 0, 10) ?></td>
                        <td><? echo $flunk_detail[$ii]['license'] ?></td>



                        <?  $flunk_detail[$ii]['cost']=-1*$flunk_detail[$ii]['cost'] ?>
                        <td><? echo $flunk_detail[$ii]['cost'] ?> </td>

                        <td>
                            <?



                            //需要把旧数据转换成大写，重新输入。
                            $flunk_detail[$ii]['license']=strtoupper($flunk_detail[$ii]['license']);


                            if (strpos($flunk_detail[$ii]['license'],"A")===0) {
                                echo $flunk_commission[$ii]=-500;

                            }
                            elseif (strpos($flunk_detail[$ii]['license'],"B")===0) {
                                echo  $flunk_commission[$ii]=-500;

                            }
                            elseif (strpos($flunk_detail[$ii]['license'],"C")===0) {
                                echo $flunk_commission[$ii]=-200;

                            }
                            elseif (strpos($flunk_detail[$ii]['license'],"E")===0) {
                                echo $flunk_commission[$ii]=-50;

                            }
                            else
                            {

                            }






                            ?>
                        </td>


                        <td><? echo $flunk_detail[$ii]['status'] ?> </td>
                        <td><? echo $flunk_detail[$ii]['payment'] ?> </td>
                        <td><? echo $flunk_detail[$ii]['graduate'] ?> </td>
                        <td><? echo $flunk_department_list[$detail[$ii]['departmentid']] ?> </td>


                    </tr>






                    <? $flunk_sum_cost[$ii]=$flunk_detail[$ii]['cost']?>
                    <? $flunk_sum_commission[$ii]=$flunk_commission[$ii]?>

                    <?php
                    ;}
                ?>

                <tr>
                    <td> </td>
                    <td> </td>
                    <td> </td>
                    <td> </td>
                    <td> </td>
                    <td> </td>
                    <td> </td>
                    <td>总金额：<? echo array_sum($sum_cost)+array_sum($flunk_sum_cost)?></td>
                    <td>提成：<? echo array_sum($sum_commission)+array_sum($flunk_sum_commission)?></td>
                    <td> </td>
                    <td>报名人数：<?echo count($detail)-count($flunk_detail)?></td>

                    <?//清除数组，不然数组又会计算到下一轮
                    unset($sum_cost);
                    unset($flunk_sum_cost);
                    unset($sum_commission);
                    unset($flunk_sum_commission);
                    ?>
                </tr>

                </tbody>
            </table>




        </div>



        <?
        ;}
    ?>















    <!--list-box end-->
            </div>

            <!--content端點01-->
        </div>
        <!--maincontent端點01-->
        <br class="clearfloat"/>
    </div>
    <!--container端點01-->
</div>










<?php include ROOT_PATH_ . "/controller/common/module/footer.php"; ?> </body>
</html>
